package picounit.loader;

import java.io.IOException;

import picounit.exception.MissingResource;

public class Properties {
    private final java.util.Properties properties;

    public Properties(String resourceName) {
        this.properties = load(resourceName);
    }

    public String get(String key) {
        String value = properties.getProperty(key);

        if (value == null) {
            throw new MissingResource("property: " + key);
        }

        return value;
    }

    private static java.util.Properties load(String resourceName) {
        try {
            java.util.Properties properties = new java.util.Properties();

            properties.load(Properties.class.getResourceAsStream(resourceName));

            return properties;
        }
        catch (IOException ioException) {
            throw new MissingResource(resourceName, ioException);
        }
        catch (NullPointerException nullPointerException) {
            throw new MissingResource(resourceName, nullPointerException);
        }
    }
}